/******************************************************************************
**
** Copyright 2011 Motorola Solutions Inc. All rights reserved.
**
** File name: 	utimer.h
**
** Description:	Timer-counter functionality related to RTOS Unit
**				Tests execution. Targets supported:
**				- ATXmega32D4 (HW)
**
** Change history:
**	
** 11/20/2011 - AK - File created. 
** 
******************************************************************************/
#ifndef __UTIMER_H__
#define __UTIMER_H__

typedef enum UTST_TLV_e
{
	LEVEL_LOW		=	TC_OVFINTLVL_LO_gc,
	LEVEL_MED		= 	TC_OVFINTLVL_MED_gc,
	LEVEL_HIGH		= 	TC_OVFINTLVL_HI_gc
}
UTST_TLV_t, * UTST_TLV_ptr;

typedef enum UTST_TST_e
{
	STATE_RUN,
	STATE_STOP
}
UTST_TST_t, * UTST_TST_ptr;

typedef struct UTST_TIMER_s
{
	TC0_t *				addr;
	unsigned short 		period;			// 0...65535 ticks ( actual inetrval depends on input frequency )
	UTST_TLV_t	 		level;			// LOW, MED, HI
	UTST_TST_t 			state;			// STOP, RUN
}
UTST_TIMER_t, * UTST_TIMER_ptr;

#define UTST_TIMER_START( __tmr__ ) 	\
	__tmr__.addr->CTRLA = ( __tmr__.addr->CTRLA & ~TC0_CLKSEL_gm ) | TC_CLKSEL_DIV8_gc
	
		
#define UTST_TIMER_STOP( __tmr__ )	\
	__tmr__.addr->CTRLA = ( __tmr__.addr->CTRLA & ~TC0_CLKSEL_gm ) | TC_CLKSEL_OFF_gc

extern void utst_init_timer(UTST_TIMER_t * tmr);

#endif 